package com.lvmama.comm.sync.utils;

import java.io.IOException;
import java.util.Properties;
 
public class Constant {

	
	private static Properties properties;
	private static volatile Constant instance=null;
	
	
	private void init() {
		try {
			properties = new Properties();
			properties.load(getClass().getResourceAsStream("/const.properties"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		// ResourceBundle.getBundle("const");
	}
	private Constant(){
		init();
	}
	public static Constant getInstance() {
		if (instance == null) {
			synchronized (Constant.class) {
				if(instance==null){
					instance = new Constant();
					//instance.init();
				}
			}
		}
		return instance;
	}

	public String getProperty(String key) {
		return getValue(key);
	}
	
	/**
	 * 获取属性
	 *
	 * @return
	 */
	public String getValue(String key) {
		return System.getProperty(key) != null?System.getProperty(key):properties.getProperty(key);
	}
	
	 /**
     * 异构数据同步数据源ID
     */
    public static enum SYNC_DATA_SOURCE {

    	superDataSource("SUPER数据源"),
    	vstDataSource("VST数据源"),
    	petDataSource("PET数据源"),
    	phpDataSource("PHP数据源"),
    	weiyouDataSource("微游数据源"),
    	bigdataDataSource("大数据数据源"),
    	esDataSource("es数据源");

    	private String cnName;

    	SYNC_DATA_SOURCE(String name) {
    		this.cnName = name;
    	}

    	public String getCode(){
    		return this.name();
    	}

    	public String getCnName(){
    		return this.cnName;
    	}

    	public static String getCnName(String code){
    		for(SYNC_DATA_SOURCE item: SYNC_DATA_SOURCE.values()){
    			if(item.getCode().equals(code))
    			{
    				return item.getCnName();
    			}
    		}
    		return code;
    	}

    	@Override
        public String toString(){
    		return "code:"+this.name()+",cnName:"+this.cnName;
    	}
    }
    
	/**
     * 异构数据同步脚本类型
     */
    public static enum SYNC_SQL_TYPE {
    	SOURCE("源SQL"),
    	TARGET("目标SQL");

    	private String cnName;

    	SYNC_SQL_TYPE(String name) {
    		this.cnName = name;
    	}

    	public String getCode(){
    		return this.name();
    	}

    	public String getCnName(){
    		return this.cnName;
    	}

    	public static String getCnName(String code){
    		for(SYNC_SQL_TYPE item: SYNC_SQL_TYPE.values()){
    			if(item.getCode().equals(code))
    			{
    				return item.getCnName();
    			}
    		}
    		return code;
    	}

    	@Override
        public String toString(){
    		return "code:"+this.name()+",cnName:"+this.cnName;
    	}
    }

    /**
     * 异构数据同步状态
     */
    public static enum SYNC_STATUS {
    	INIT("初始化"),
    	FAIL("失败"),
    	RUNNING("执行中"),
    	SUCCESS("成功");

    	private String cnName;

    	SYNC_STATUS(String name) {
    		this.cnName = name;
    	}

    	public String getCode(){
    		return this.name();
    	}

    	public String getCnName(){
    		return this.cnName;
    	}

    	public static String getCnName(String code){
    		for(SYNC_STATUS item: SYNC_STATUS.values()){
    			if(item.getCode().equals(code))
    			{
    				return item.getCnName();
    			}
    		}
    		return code;
    	}

    	@Override
        public String toString(){
    		return "code:"+this.name()+",cnName:"+this.cnName;
    	}
    }

    /**
     * 异构数据同步脚本类型
     */
    public static enum SYNC_SCRIPT_TYPE {
    	SQL("数据库脚本"),
    	GROOVY("GROOVY脚本");

    	private String cnName;

    	SYNC_SCRIPT_TYPE(String name) {
    		this.cnName = name;
    	}

    	public String getCode(){
    		return this.name();
    	}

    	public String getCnName(){
    		return this.cnName;
    	}

    	public static String getCnName(String code){
    		for(SYNC_SCRIPT_TYPE item: SYNC_SCRIPT_TYPE.values()){
    			if(item.getCode().equals(code))
    			{
    				return item.getCnName();
    			}
    		}
    		return code;
    	}

    	@Override
        public String toString(){
    		return "code:"+this.name()+",cnName:"+this.cnName;
    	}
    }



    /**会员级别*/
    public static enum USER_GRADE {
		DIAMOND("钻石"),
		GOLD("黄金"),
		PLATINUM("白金"),
		NORMAL("普通");

		private String cnName;
		USER_GRADE(String name){
			this.cnName=name;
		}
		public String getCode(){
			return this.name();
		}
		public String getCnName(){
			return this.cnName;
		}
		public static String getCnName(String code){
			for(USER_GRADE item:USER_GRADE.values()){
				if(item.getCode().equals(code))
				{
					return item.getCnName();
				}
			}
			return code;
		}
		@Override
        public String toString(){
			return this.name();
		}
    }
    
    /**
     * 异构数据同步触发类型
     */
    public static enum TRIGGER_TYPE {

    	INSERT("新增"),
    	UPDATE("修改"),
    	DELETE("删除");

		private String cnName;

		TRIGGER_TYPE(String name) {
			this.cnName = name;
		}

		public String getCode(){
			return this.name();
		}

		public String getCnName(){
			return this.cnName;
		}

		public static String getCnName(String code){
			for(TRIGGER_TYPE item: TRIGGER_TYPE.values()){
				if(item.getCode().equals(code))
				{
					return item.getCnName();
				}
			}
			return code;
		}

		@Override
        public String toString(){
			return "code:"+this.name()+",cnName:"+this.cnName;
		}
	}
    
    /**
	 * 用来区分操作的机器
	 *
	 * @return
	 */
	public String getServerName() {
		return getValue("serverName");
	}
	
	public String getSyncJarPath(){
		return getValue("syncJarPath");
	}
}

